import { defineManifest } from '@crxjs/vite-plugin'
import packageData from '../package.json'

//@ts-ignore
const isDev = process.env.NODE_ENV == 'development'

export default defineManifest({
  name: `${packageData.displayName || packageData.name}${isDev ? ` ➡️ Dev` : ''}`,
  description: packageData.description,
  version: packageData.version,
  manifest_version: 3,
  icons: {
    128: 'img/icon-128.png',
  },
  action: {
    default_icon: 'img/icon-128.png',
  },
  options_page: 'options.html',
  devtools_page: 'devtools.html',
  background: {
    service_worker: 'src/background/index.ts',
    type: 'module',
  },
  content_scripts: [
    {
      matches: ['http://*/*', 'https://*/*'],
      js: ['src/contentScript/index.ts'],
      "run_at": "document_end"
    },
  ],
  side_panel: {
    default_path: 'sidepanel.html',
  },
  web_accessible_resources: [
    {
      resources: ['img/icon-128.png'],
      "matches": ["<all_urls>"]
    },
    {
      "resources": [
        "tesseract/*.wasm', 'tesseract/*.js'],"
      ],
      "matches": ["<all_urls>"]
    }
  ],
"content_security_policy": {
    "extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'; worker-src 'self'"
  },
  host_permissions: ['<all_urls>'],
  permissions: ['activeTab',
    'scripting',
    'tabs',
    'storage',
    'downloads',
    'contextMenus',
    'commands',
    'webRequest',
    'clipboardWrite',
    'clipboardRead',
    'webNavigation',
    'notifications',
    'sidePanel',
  ],
  commands: {
    'short-input': {
      suggested_key: {
        default: 'Ctrl+Q',
        mac: 'Command+S',
      },
      description: '快捷输入',
    },
    'short-input-zipcode': {
      suggested_key: {
        default: 'Shift+Alt+Q',
        mac: 'Command+Shift+Q',
      },
      description: '快捷输入邮编',
    },
    'short-open-panel': {
      suggested_key: {
        default: 'Shift+Alt+E',
        mac: 'Command+Shift+E',
      },
      description: '快捷打开侧边栏',
    },
    'get-selected-text': {
      suggested_key: {
        default: 'Shift+Alt+W',
      },
      description: 'Get selected text',
    },
  },
})
